import { constructMockData } from '@/mock/mock'
import { AxiosRequestConfig } from 'axios'
import { dayjs } from 'element-plus'
import Mock from 'mockjs'
/**
 * @description 产品黏性-直接访问率
 */
export const directVisitRateRes = (config: AxiosRequestConfig<any>) => {
  const { dateRange, type } = JSON.parse(config.data)
  // 计算需要多少天的数据
  const [startDate, endDate] = dateRange
  const diffDays = dayjs(endDate).diff(startDate, 'day') + 1
  // 生成数据
  const data = Array.from({ length: diffDays }).map((item, index) => {
    return {
      type,
      date: dayjs(startDate).add(index, 'day').format('YYYY-MM-DD'),
      hourlyDirectRate: Mock.Random.integer(0, 100),
      dailyDirectRate: Mock.Random.integer(0, 100),
    }
  })
  return constructMockData(data)
}
/**
 * @description 产品黏性-跳出率
 */
export const bounceRateRes = (config: AxiosRequestConfig<any>) => {
  const { dateRange, type } = JSON.parse(config.data)
  // 计算需要多少天的数据
  const [startDate, endDate] = dateRange
  const diffDays = dayjs(endDate).diff(startDate, 'day') + 1
  // 生成数据
  const data = Array.from({ length: diffDays }).map((item, index) => {
    return {
      type,
      date: dayjs(startDate).add(index, 'day').format('YYYY-MM-DD'),
      hourlyBounceRate: Mock.Random.integer(0, 100),
      dailyBounceRate: Mock.Random.integer(0, 100),
    }
  })
  return constructMockData(data)
}
/**
 * @description 产品黏性-人均页面浏览量PV
 */
export const pagesPerVisitRes = (config: AxiosRequestConfig<any>) => {
  const { dateRange, type } = JSON.parse(config.data)
  // 计算需要多少天的数据
  const [startDate, endDate] = dateRange
  const diffDays = dayjs(endDate).diff(startDate, 'day') + 1
  // 生成数据
  const data = Array.from({ length: diffDays }).map((item, index) => {
    return {
      type,
      date: dayjs(startDate).add(index, 'day').format('YYYY-MM-DD'),
      hourlyPagesPerVisit: Mock.Random.integer(0, 10),
      dailyPagesPerVisit: Mock.Random.integer(0, 10),
    }
  })
  return constructMockData(data)
}
/**
 * @description 产品黏性-平均访问时长
 */
export const averageVisitTimeRes = (config: AxiosRequestConfig<any>) => {
  const { dateRange, type } = JSON.parse(config.data)
  // 计算需要多少天的数据
  const [startDate, endDate] = dateRange
  const diffDays = dayjs(endDate).diff(startDate, 'day') + 1
  // 生成数据
  const data = Array.from({ length: diffDays }).map((item, index) => {
    return {
      type,
      date: dayjs(startDate).add(index, 'day').format('YYYY-MM-DD'),
      hourlyAverageVisitTime: Mock.Random.integer(0, 3600),
      dailyAverageVisitTime: Mock.Random.integer(0, 3600),
    }
  })
  return constructMockData(data)
}
/**
 * @description 产品黏性-用户生命周期
 */
export const userLifeTimeRes = (config: AxiosRequestConfig<any>) => {
  const { dateRange, type } = JSON.parse(config.data)
  // 计算需要多少天的数据
  const [startDate, endDate] = dateRange
  const diffDays = dayjs(endDate).diff(startDate, 'day') + 1
  // 生成数据
  const data = Array.from({ length: diffDays }).map((item, index) => {
    return {
      type,
      date: dayjs(startDate).add(index, 'day').format('YYYY-MM-DD'),
      hourlyUserLifeTime: Mock.Random.integer(0, 36000),
      dailyUserLifeTime: Mock.Random.integer(0, 36000),
    }
  })
  return constructMockData(data)
}
/**
 * @description 产品黏性-最高同时在线人数
 */
export const maxConcurrentUsersRes = (config: AxiosRequestConfig<any>) => {
  const { dateRange, type } = JSON.parse(config.data)
  // 计算需要多少天的数据
  const [startDate, endDate] = dateRange
  const diffDays = dayjs(endDate).diff(startDate, 'day') + 1
  // 生成数据
  const data = Array.from({ length: diffDays }).map((item, index) => {
    return {
      type,
      date: dayjs(startDate).add(index, 'day').format('YYYY-MM-DD'),
      hourlyMaxConcurrentUsers: Mock.Random.integer(0, 30000),
      dailyMaxConcurrentUsers: Mock.Random.integer(0, 30000),
    }
  })
  return constructMockData(data)
}
